/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package org.genew.squadra.xml.model.builder;

import java.util.List;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import org.genew.squadra.xml.model.nav.Nav;
import org.genew.squadra.xml.model.nav.Navhref;

/**
 *
 * @author Matteo
 */
public class NavBuilder implements Builder {
    
    public static void buildNav(Nav nav, XMLStreamWriter xmlNav) throws XMLStreamException{
        xmlNav.writeStartDocument("UTF-8","1.0");
        xmlNav.writeStartElement("html");
        //xmlNav.writeAttribute("profile", "http://www.idpf.org/epub/30/profile/content/");
        xmlNav.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml");
            xmlNav.writeStartElement("head");
                xmlNav.writeStartElement("title");
                xmlNav.writeCharacters(nav.getIndice());
                xmlNav.writeEndElement();
//                xmlNav.writeStartElement("link");
//                xmlNav.writeAttribute("href","../css/toc.css");
//                xmlNav.writeAttribute("rel","stylesheet");
//                xmlNav.writeAttribute("type","text/cs");
//                xmlNav.writeEndElement();
            xmlNav.writeEndElement();
            
            xmlNav.writeStartElement("body");
                xmlNav.writeStartElement("section");
                xmlNav.writeAttribute("class", "classe-qualcosa-per-css");
                    xmlNav.writeStartElement("header");
                        xmlNav.writeStartElement("h1");
                        xmlNav.writeCharacters("Indice");
                        xmlNav.writeEndElement();
                    xmlNav.writeEndElement(); //Chiudi Header
                    xmlNav.writeStartElement("nav");
                    xmlNav.writeAttribute("xmlns:epub", "http://www.idpf.org/2007/ops");
                    xmlNav.writeAttribute("epub:type", Nav.TYPE);
                    xmlNav.writeAttribute("id", Nav.ID);
                    buildNavHref(nav.getHrefs(), xmlNav);
                    xmlNav.writeEndElement(); //Chiudi Nav
                xmlNav.writeEndElement(); // chiude SEction
            xmlNav.writeEndElement(); // Chiude Body
        xmlNav.writeEndElement(); // chiude html
        xmlNav.writeEndDocument();
        
    }
    
    private static void buildNavHref(List<Navhref> navhref, XMLStreamWriter xmlNav) throws XMLStreamException{
        xmlNav.writeStartElement("ol");
        int i;
        int max = navhref.size();
        for(i=0; i< max; i++){
            Navhref temp = navhref.get(i);
            xmlNav.writeStartElement("li");
            xmlNav.writeAttribute("class", temp.getNavClass());
            xmlNav.writeAttribute("id", temp.getId());
                xmlNav.writeStartElement("a");
                xmlNav.writeAttribute("href", temp.getHref());
                xmlNav.writeCharacters(temp.getContent());
                xmlNav.writeEndElement();
            xmlNav.writeEndElement(); //Chiude Li
        }
        xmlNav.writeEndElement(); //Chiude ol
    }
}
